﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MyServer.Common;
using System.Net;
using System.Net.Sockets;
using FrameWork.Setting;

namespace MyServer.TcpIP
{
    [SettingParentDefine]
    public class TcpIpDataListener:DataListenerBase
    {
        private object LockObj = new object();
        private object LockObj2 = new object();
        public override int CheckDataAvilable(object Client)
        {
            lock (LockObj)
            {
                if (Client == null)
                    return 0;
                lock (Client)
                {
                    TcpClient c = (TcpClient)Client;
                    return c.Available;
                }
            }
        }

        public override bool ClearData(object Client)
        {
            lock (LockObj2)
            {
                if (Client == null)
                    return false;
                lock (Client)
                {
                    TcpClient c = (TcpClient)Client;
                    byte[] tmpbuffer = new byte[c.Available];
                    c.GetStream().Read(tmpbuffer, 0, tmpbuffer.Length);
                    return true;
                }
            }
        }

        public TcpIpDataListener(TcpIpCenter Center) : base(Center) { }


    }
}
